/* eslint-disable */
// 全部都是 api
// 引入路由 koa-router
const router = require('koa-router')();

// 引入 controller
const {
    userApi
} = require('../../../controller/user/user');

// 引入权限验证中间件
const { check } = require('../../../middleware/routercheck');
// 引入验证用户是否有效中间件
const { checkStatus } = require('../../../middleware/isStatus');
// 引入验证数据是否匹配中间件
const { veri } = require('../../../middleware/checkData');

router.post(
    '/user/login',
    veri(['username', 'password'], 'Non empty', 'request'),
    checkStatus,
    userApi);
router.get(
    '/user/list',
    veri(['pageNum', 'pageSize'], 'Non empty', 'query'),
    check('getuser'),
    userApi);
router.get('/user/byid/:id', veri(['id'], 'Non empty', 'params'), check('getuser'), userApi);
router.get('/user/searchuser', veri(['pageNum', 'pageSize'], 'Non empty', 'query'), veri(['username'], 'Non empty', 'request'), check('getuser'), userApi); // 模糊查询
router.post(
    '/user/register',
    veri(['username', 'password', 'role_id', 'nickname'], 'Non empty', 'request'),
    check('createuser'),
    userApi); // 添加用户
router.put(
    '/user/edit/:id',
    veri(['id'], 'Non empty', 'params'),
    veri(['sex',], 'sex', 'request'),
    veri(['phone',], 'phone', 'request'),
    veri(['mail',], 'mail', 'request'),
    check('edituser'),
    userApi
);
router.put(
    '/user/editpass/:id',
    veri(['username', 'password', 'newpassword'], 'Non empty', 'request'),
    check('edituser'),
    userApi
);

router.delete('/user/remove/:id', veri(['id'], 'Non empty', 'params'), check('removeuser'), userApi);
router.post('/user/activation/:id', veri(['id'], 'Non empty', 'params'), check('edituser'), userApi);

module.exports = router;